<template>
	<div class="space-device">
		<div>
			<label>{{ $t('route.Map') }}</label>
			<div></div>
			<button><img /><label>{{ $t('route.Spare_map') }}</label></button>
		</div>

		<div>
			<el-select @change='kindChange' style="margin-left: 10px;" v-model="query.kind" :placeholder="$t('route.Please_select_the_type')">
				<el-option v-for="item in kindList" :key="item" :label="item" :value="item">
				</el-option>
			</el-select>
			<div v-if="false" class="div-handle-right">
				<el-button>{{ $t('route.search') }}</el-button>
				<input :placeholder="$t('route.keyword')" />
			</div>
		</div>

		<div>
			<div v-for="(item,index) in kindDeviceList">
				<div :id="'echart-'+index" style="height: 400px;width: 700px;"></div>
			</div>
		</div>


	</div>
</template>

<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import * as echarts from 'echarts';
	import Constant from '../../js/common/constant.js'
	import i18n from "../../i18n";

	export default {
		data() {
			return {
				query: {
					kind: null
				},
				kindList: [],
				kindDeviceList: []
			};
		},
		methods: {
			kindChange() {
				this.getKindDeviceReport();
			},
			getKindDeviceReport() {
				http.post(api.GET_KIND_DEVICE_REPORT, {
					adminId: this.$store.state.user.id,
					kind: this.query.kind == i18n.global.t('route.All_categories') ? null : this.query.kind,
				}, data => {
					this.kindDeviceList = data.data;
					setTimeout(() => {
						for (var i = 0; i < this.kindDeviceList.length; i++) {
							this.initEchart1(i, this.kindDeviceList[i]);
						}
					}, 500);

				})
			},

			initEchart1(index, data) {
				var myChart = echarts.init(document.getElementById("echart-" + index));
				var dataAry = [];
				for (var item of data.kindCountList) {
					dataAry.push({
						name: item.kind,
						value: item.count
					})
				}
				var title;
				if (data.workshop) {
					title = i18n.global.t('route.Workshop') + data.workshop
				} else {
					title = i18n.global.t('route.Warehouse') + data.store
				}
				var option = CommonUtils.initPieOption1(title, dataAry, i18n.global.t('route.Device_category'), i18n.global.t('route.platform'));
				myChart.setOption(option);
				return;
			},
		},

		created() {
			this.kindList = [i18n.global.t('route.All_categories'), ...Constant.DEVICE_KIND];
			this.getKindDeviceReport();
		},

	};
</script>
<style lang="scss" scoped>
	.space-device {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;

		>div:nth-of-type(1),
		>div:nth-of-type(2) {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;
		}

		>div:nth-of-type(1) {


			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}

			}
		}

		>div:nth-of-type(2) {

			.div-handle-right {
				flex: 1;
				flex-direction: row-reverse;
				text-align: right;
				display: flex;
				align-items: center;

				>input:nth-of-type(1) {
					border: 1px solid #eeeeee;
					font-size: 15px;
					width: 150px;
					padding: 5px 8px;
					outline: none;
				}

				>button {
					color: #A866FF;
					margin-left: 10px;
					padding: 4px 20px;
				}
			}
		}

		>div:nth-of-type(3) {
			margin-top: 5px;

			>div {
				margin-right: 10px;
				width: 700px;
				height: 400px;
				display: inline-block;
				background-color: #ffffff;
				padding: 20px;
				border-radius: 5px;
			}

		}


	}
</style>
